package com.aceitunaproject.mapdisplay.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * DisplayConfiguration Implementation factory.
 * @author Federico Bergstein
 */
public class DisplayConfigurationProvider {

	private static final Logger LOGGER = Logger.getLogger(DisplayConfigurationProvider.class);
	
	private static final String PROPERTIES = "/META-INF/map-display-config.properties";
	
	/*
	 * Returns a DisplayConfiguration Implementation.
	 */
	public static DisplayConfiguration getConfig() {
		Properties props= setUp(PROPERTIES);
		return DefaultDisplayConfiguration.getInstance(props);
	}
	
	public static Properties setUp(String propertiesLocation) {
		
		InputStream is = DisplayConfigurationProvider.class.getResourceAsStream(propertiesLocation);
		Properties properties = new Properties();
		try {
			properties.load(is);
		} catch (IOException e) {
			LOGGER.warn("Failed to load properties from [" + propertiesLocation + "].", e);
		} catch (NullPointerException e) {
			LOGGER.warn("Failed to load properties from [" + propertiesLocation + "].", e);
		}
		
		return properties;
	}
}
